package com.zhejiangzhengyuan.municipal_pumping_station.controller;

import com.zhejiangzhengyuan.municipal_common.entity.PumpEstimatedValue;
import com.zhejiangzhengyuan.municipal_common.entity.vo.GasCheckVo;
import com.zhejiangzhengyuan.municipal_common.response.ResponseVo;
import com.zhejiangzhengyuan.municipal_common.service.PumpEstimatedValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;

/**
 * @author :linju
 * @since  on : 2019/12/14
 */
@RestController
@Slf4j
@RequestMapping("/station/pumpStationDataManagement")
@Api(tags = "泵站数据管理")
public class DataManagementCtroller {
    @Autowired private PumpEstimatedValueService pumpEstimatedValueService;

    @ApiOperation("查询检测值的液位")
    @GetMapping("/selectPumpEstimatedValue")
    public ResponseVo selectPumpEstimatedValue() {
        List<PumpEstimatedValue> all = pumpEstimatedValueService.selectPumpEstimatedValue();
        return ResponseVo.successWithData(all);
    }

    @ApiOperation("模糊查询检测值的液位")
    @GetMapping("/selectVaguePumpEstimatedValue")
    public ResponseVo selectVaguePumpEstimatedValue(String pageNo,String pageSize,String name,String startTime,String endTime) throws ParseException {
        List<PumpEstimatedValue> all = pumpEstimatedValueService.selectVaguePumpEstimatedValue(name,startTime,endTime);
        return ResponseVo.successWithData(all);
    }

    @ApiOperation("查询检测值的电流")
    @GetMapping("/selectPumpElectricityValue")
    public ResponseVo selectPumpElectricityValue() {
        List<PumpEstimatedValue> all = pumpEstimatedValueService.selectPumpElectricityValue();
        return ResponseVo.successWithData(all);
    }

    @ApiOperation("模糊查询检测值的电流")
    @GetMapping("/selectVaguePumpElectricityValue")
    public ResponseVo selectVaguePumpElectricityValue(String pageNo,String pageSize,String name,String startTime,String endTime) throws ParseException {
        List<PumpEstimatedValue> all = pumpEstimatedValueService.selectVaguePumpElectricityValue( name,startTime,endTime);
        return ResponseVo.successWithData(all);
    }

    @ApiOperation("查询泵站检测的气体")
    @GetMapping("/selectPumpGasValue")
    public ResponseVo selectPumpGasValue() {
        List<GasCheckVo> all = pumpEstimatedValueService.selectPumpGasValue();
        return ResponseVo.successWithData(all);
    }

    @ApiOperation("模糊查询泵站检测的气体")
    @GetMapping("/selectVaguePumpGasValue")
    public ResponseVo selectVaguePumpGasValue(String pageNo,String pageSize,String name,String startTime,String endTime) {
        List<GasCheckVo> all = null;
        try {
            all = pumpEstimatedValueService.selectVaguePumpGasValue(name,startTime,endTime);
        } catch (ParseException e) {
            return ResponseVo.errorWithException(e);
        }
        return ResponseVo.successWithData(all);
    }

    @ApiOperation("导出检测值的液位")
    @GetMapping("/exportPumpEstimatedValue")
    public void exportPumpEstimatedValue(HttpServletResponse response) {
        pumpEstimatedValueService.exportPumpEstimatedValue(response);
    }

    @ApiOperation("导出检测值的电流")
    @GetMapping("/exportPumpElectricityValue")
    public void exportPumpElectricityValue(HttpServletResponse response) {
        pumpEstimatedValueService.exportPumpElectricityValue(response);
    }

    @ApiOperation("导出泵站检测的气体")
    @GetMapping("/exportPumpGasValue")
    public void exportPumpGasValue(HttpServletResponse response) {
        pumpEstimatedValueService.exportPumpGasValue(response);
    }

    @ApiOperation("查询泵站过去24小时设备故障次数")
    @GetMapping("/getDeviceBreakdownCount")
    public ResponseVo getDeviceBreakdownCount() {
        List deviceBreakdownCount = pumpEstimatedValueService.getDeviceBreakdownCount();
        return ResponseVo.successWithData(deviceBreakdownCount);
    }

    @ApiOperation("查询泵站过去24小时设备液位异常次数")
    @GetMapping("/getDeviceAnalyzeCount")
    public ResponseVo getDeviceAnalyzeCount() {
        List deviceBreakdownCount = pumpEstimatedValueService.getDeviceAnalyzeCount();
        return ResponseVo.successWithData(deviceBreakdownCount);
    }
}
